home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra_2 / nadir11.zip / PHONEL.N < prev    next >
Text File  |  1995-11-08  |  8KB  |  238 lines

  1. Define PhoneLoad()
  2. //  use this with n -ePhoneLoad -Uphone.dat <text filename listing>
  3. //  macro reads the text phone list and inserts into the univ file
  4. {
  5.     SymRemove("univ");
  6.     SymCreate("univ",,,2048,24);
  7.     while (!LineGet(&buff)) {
  8.         name = StrTrim(StrSubs(buff, 0, 60));
  9.         phoneNo = StrTrim(StrSubs(buff, 60));
  10.         Explode(name, ",", &nameLast, &nameFirst);
  11.  
  12. //  ph^[code]^phn                   = the phone number
  13. //  ph^[code]^naf                   = name first
  14. //  ph^[code]^nal                   = name last
  15. //  ph_naf^[nameFirst]^[code]       = "y"       (list by name first)
  16. //  ph_nal^[nameLast]^[code]        = "y"       (list by name last)
  17.  
  18.         code += 1;
  19.         if (nameFirst)
  20.             univ^ph^[code]^naf = nameFirst;
  21.         univ^ph^[code]^nal = nameLast;
  22.         univ^ph^[code]^phn = phoneNo;
  23.     }
  24.     PhoneKeyRebuild();
  25. }
  26. Define PhoneFmtNal(key) {
  27.     Explode(key, "^", , &code);
  28.     return univ^ph^[code]^nal. "\t". univ^ph^[code]^naf. "\t". univ^ph^[code]^phn;
  29. }
  30. Define PhoneFmtNaf(key) {
  31.     Explode(key, "^", , &code);
  32.     return univ^ph^[code]^naf. "\t". univ^ph^[code]^nal. "\t". univ^ph^[code]^phn;
  33. }
  34. Define PhoneSelCreate(scr)
  35. {
  36.     if (parm^phone^ord == "f") {
  37.         SdSelect(scr, "sel",  1, 0, 1, 53, 10, ,
  38.                     "univ^ph_naf^", , "PhoneFmtNaf", 130);
  39.         SdFieldCols(scr, "sel", 15, 20, 15);
  40.     }
  41.     else {
  42.         SdSelect(scr, "sel",  1, 0, 1, 53, 10, , 
  43.                     "univ^ph_nal^", , "PhoneFmtNal", 130);
  44.         SdFieldCols(scr, "sel", 20, 15, 15);
  45.     }
  46. }
  47. Define PhoneSelCode(scr)
  48. {
  49. // returns the code of the currently selected person 
  50.     Explode(SdFieldGet(scr, "sel"), "^", &name, &code);
  51.     return code;
  52. }
  53. Define PhoneSelFieldSet(scr, code)
  54. {
  55.     SdFieldSet(scr, "sel", 
  56.                parm^phone^ord == "f" 
  57.                     ? StrToLower(univ^ph^[code]^naf) . "^" . code
  58.                     : StrToLower(univ^ph^[code]^nal) . "^" . code);
  59. }
  60. Define PhoneSelNext(code)
  61. {
  62.     if (parm^phone^ord == "f") {
  63.         pre = "ph_naf";
  64.         val = StrToLower(univ^ph^[code]^naf);
  65.     }
  66.     else {
  67.         pre = "ph_nal";
  68.         val = StrToLower(univ^ph^[code]^nal);
  69.     }
  70.     Explode(next(univ^[pre]^[val]^[code]), "^", &npre, , &ncode);
  71.     if (npre == pre)
  72.         return ncode;
  73.     Explode(prev(univ^[pre]^[val]^[code]), "^", &npre, , &ncode);
  74.     if (npre == pre)
  75.         return ncode;
  76.     return "";
  77. }
  78. Define PhoneList()
  79. {
  80.     scr = SdCreate("", -1, -1, 10, 55, "Phone List");
  81.     SdMenu(scr, "main", 1, "Entry",      "e", 121, 
  82.                         1, "Options",    "o", 120,
  83.                         1, "Utilities",  "u", 125);
  84.     SdPopup(scr, "mtce", 121, 1, "Modify",     "m", 122,
  85.                               1, "Add",        "a", 123,
  86.                               1, "Remove",     "r", 124);
  87.     SdPopup(scr, "util", 125, 1, "Key Rebuild","k", 126);
  88.     PhoneSelCreate(scr);
  89.  
  90.     while (action != 2 && action != 3) {
  91.         switch(action = SdEdit(scr)) {
  92.         case 120:
  93.             code = PhoneSelCode(scr);
  94.             if (PhoneOpt() == 1)
  95.                 PhoneSelCreate(scr);
  96.                 PhoneSelFieldSet(scr, code);
  97.             break;
  98.         case 130:                       // double click select box
  99.         case 122:
  100.             if (PhoneMod(code = PhoneSelCode(scr)) == 1)
  101.                 PhoneSelFieldSet(scr, code);
  102.             break;
  103.         case 123:
  104.             if (PhoneAdd(&code) == 1)
  105.                 PhoneSelFieldSet(scr, code);
  106.             break;
  107.         case 124:
  108.             code = PhoneSelCode(scr);
  109.             if (MsgYesNo("", 
  110.                            "Delete " . univ^ph^[code]^naf . " "
  111.                                      . univ^ph^[code]^nal 
  112.                                      . ", are you sure ?") == 1) {
  113.                 nextCode = PhoneSelNext(code);
  114.                 PhoneDel(code);
  115.                 PhoneSelFieldSet(scr, nextCode);
  116.             }
  117.             break;
  118.         case 126:
  119.             code = PhoneSelCode(scr);
  120.             PhoneKeyRebuild();
  121.             PhoneSelFieldSet(scr, code);
  122.             break; 
  123.         }
  124.     }
  125.     SdDestroy(scr);    
  126. }
  127. Define PhoneOpt()
  128. {
  129.     scr = SdCreate("", -2, -2, 6, 32, "Options");
  130.     SdPrompt(scr,            1,  2, "Order By:");
  131.     SdRadio (scr, "r0",   1, 1, 12, 20, &parm^phone^ord, "Last Name", "l");
  132.     SdRadio (scr, "r1",   1, 2, 12, 20, &parm^phone^ord, "First Name", "f");
  133.     SdButton(scr, "ok",   1, 4, 4, 10, "OK", "", 1);
  134.     SdButton(scr, "can",  1, 4, 18, 10, "Cancel", "", 2);
  135.     if ((action = SdEdit(scr)) == 1) {
  136.         SdUpdate(scr);
  137.     }
  138.     SdDestroy(scr);    
  139.     return action;
  140. }
  141. Define PhoneNalMandatory(hand, value, name) {
  142.     if (!value) {
  143.         MsgWait("", "Last Name must be entered");
  144.         return 1;
  145.     }
  146. }
  147. Define PhonePhnMandatory(hand, value, name) {
  148.     if (!value) {
  149.         MsgWait("", "Phone Number must be entered");
  150.         return 1;
  151.     }
  152. }
  153. Define PhoneKeysSet(code, value) {
  154. /*
  155.     set or delete the keys for code.
  156.     if value is null, keys are deleted, else if "y", keys are set
  157. */
  158.     naf = univ^ph^[code]^naf;
  159.     nal = univ^ph^[code]^nal;
  160.     univ^ph_naf^[StrToLower(naf)]^[code]    = naf ? value : "";
  161.     univ^ph_nal^[StrToLower(nal)]^[code]    = value;
  162. }
  163. Define PhoneModScrCreate(title)
  164. {
  165.     scr = SdCreate("", -2, -2, 7, 36, title);
  166.     SdPrompt(scr,            1,  2, "First Name:");
  167.     SdString(scr, "naf", 1, 1,  14, 20);
  168.     SdPrompt(scr,            2,  2, "Last Name:");
  169.     SdString(scr, "nal", 1, 2,  14, 20, , "PhoneNalMandatory");
  170.     SdPrompt(scr,            3,  2, "Phone No:");
  171.     SdString(scr, "phn", 1, 3,  14, 20, , "PhonePhnMandatory");
  172.     SdButton(scr, "ok",   1, 5, 6, 10, "OK", "", 1);
  173.     SdButton(scr, "can",  1, 5, 20, 10, "Cancel", "", 2);
  174.     return scr;
  175. }
  176. Define PhoneModField(name, scr, code)
  177. /*
  178.     name is either Var or VarChg
  179. */
  180. {
  181.     ["SdField" . name](scr, "naf", &univ^ph^[code]^naf, 
  182.                     "nal", &univ^ph^[code]^nal,
  183.                     "phn", &univ^ph^[code]^phn);
  184. }
  185. Define PhoneMod(code)
  186. {
  187.     scr = PhoneModScrCreate("Modify Entry");
  188.     PhoneModField("Var", scr, code);
  189.     if ((action = SdEdit(scr)) == 1) {
  190.         PhoneKeysSet(code);
  191.         SdUpdate(scr);
  192.         PhoneKeysSet(code, "y");
  193.     }
  194.     SdDestroy(scr);    
  195.     return action;
  196. }
  197. Define PhoneAdd(code)
  198. {
  199.     scr = PhoneModScrCreate("Add Entry");
  200.     if ((action = SdEdit(scr)) == 1) {
  201.         Explode(prev(univ^ph^[999999999]), "^", &type, &code);
  202.         code = type != "ph" ? 1 : code + 1;
  203.         PhoneModField("VarChg", scr, code);
  204.         SdUpdate(scr);
  205.         PhoneKeysSet(code, "y");
  206.     }
  207.     SdDestroy(scr);    
  208.     return action;
  209. }
  210. Define PhoneDel(code) {
  211.     PhoneKeysSet(code, "");
  212.     while (field = NextField("univ", "ph", code, field))
  213.         univ^ph^[code]^[field] = "";
  214. }
  215. Define PhoneKeyRebuild() {
  216.     scr = MsgCreate("Phone List Key Rebuild");
  217.     cnt = 0;
  218.     key = "";
  219.     while (key = SymNext("univ", key, "ph_")) {     /* remove them all */
  220.         if (!((cnt += 1) % 50) && (abort = MsgShow(scr, "Deleting " . key)))
  221.             break;
  222.         univ^ph_[key] = "";
  223.     }
  224.     cnt = 0;
  225.     if (!abort) {
  226.         code = "";
  227.         while (code = SymNext("univ", code, "ph^")) {
  228.             Explode(code, "^", &code);
  229.             if (!((cnt += 1) % 50) && (abort = MsgShow(scr, "Rebuild " . code)))
  230.                 break;
  231.             PhoneKeysSet(code, "y");
  232.             code += 1;
  233.         }
  234.     }
  235.     MsgDestroy(scr);
  236. }
  237.  
  238.